<template>
	<view>
		<!-- 自我检测题 -->
		<view class="exerciseBg">
			<exam-widght
			:dataList='questionList' 
			@select='selectItem' 
			@selectFinish='selectFinish' 
			>
			</exam-widght>
		</view>
	</view>
</template>

<script>
	import examWidght from '@/components/Li-ExamWidght/Li-ExamWidght.vue';
		import * as practiceApi from '@/common/apis/practicetest-api.js';
	export default {
		components: {
			examWidght
		},
		data() {
			return {
				practiceId: '',
				questionList: [],
				
			};
		},
		async onLoad(op) {
			this.practiceId = op.id;
			this.getExamQuestionsList();
		},
		methods: {
			getExamQuestionsList() {
				practiceApi.examQuestionsList({
						id: this.practiceId
					})
					.then(res => {
						uni.setNavigationBarTitle({
							title: res.examName + '试题'
						})
						var questionList=res.examQuestions;
						for (var question of questionList) {
							//创建答题选项对象
							let {optA, optB, optC, optD} = {
								optA : {
									'fldOptionText' : question.optionA,
									'fldOptionIndex' : 1
								},
								optB : {
									'optionID' : question.id+'B',
									'fldOptionText' : question.optionB,
									'fldOptionIndex' : 2
								},
								optC : {
									'fldOptionText' : question.optionC,
									'fldOptionIndex' : 3
								},
								optD : {
									'fldOptionText' : question.optionD,
									'fldOptionIndex' : 4
								},
							}
							
							//重组答题选项list
							question.questionID =  question.id;
							question.fldName = question.questionsContent;
							question.fldAnswer = null;
							question.questionType = 0;
							question.QuestionOptionList =  [optA, optB, optC, optD];
						}
						this.questionList = questionList
					});
			},
			
			selectItem(item) {
				console.log("-----selectItem------")
				console.log(item)
			},
				
			selectFinish(item) {
				console.log("-----selectFinish------")
				console.log(item)
				let index = item.newItem.index + 1;
			}
		}
	};
</script>

<style lang="scss" scoped>
	.exerciseBg {
		margin: 20upx;
		border-radius: 16upx;
		padding: 20upx;
		background-color: #fff;
	}
</style>
